package ceshi;

import java.text.NumberFormat;
public class Test3 {
    /**
     * 驼峰转蛇形
     */
    public static class CamelChangeSnake {
        public String CamelChangeSnake(String string){
            char[] array= string.toCharArray();
            string = string.toLowerCase();
            StringBuffer stringBuffer = new StringBuffer(string);
            char[] array2 = string.toCharArray();
            int index = 0;
            for (int i = 0; i < array.length; i++){
                if (!(array[i] == array2[i]) && i != 0){
                    stringBuffer.insert(i + index, "_");
                    index++;
                }
            }
            return stringBuffer.toString();
        }
    }


    /**
     * 蛇形转驼峰
     */
    public static class SnakeChangeCamel {
        public String SnakeChangeCamel(String string){
            String[] str = string.split("_");
            string = "";
            for (int i = 0; i < str.length; i++){
                if (i != 0){
                    char[] array = str[i].toCharArray();
                    str[i] = "";
                    array[0] = (char) (array[0] - 32);
                    for (int j = 0; j < array.length; j++){
                        str[i] += array[j];
                    }
                }
                string += str[i];
            }
            return string;
        }
    }
    /**
     * 将货币数字以千分位的方式表示
     */
    public static void changeNumber() {
        NumberFormat numberFormat = NumberFormat.getNumberInstance();
        System.out.println(numberFormat.format(134312445.12));
    }
    public static void main(String[] args) {
        CamelChangeSnake camelToSnake = new CamelChangeSnake();
        System.out.println(camelToSnake.CamelChangeSnake("camelChangeSnake"));
        SnakeChangeCamel snakeChangeCamel = new SnakeChangeCamel();
        System.out.println(snakeChangeCamel.SnakeChangeCamel("camel_change_snake"));
        changeNumber();
    }
}


